package servlet;

import constant.ConstantTable;
import impl.UserImpl;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.charset.Charset;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Random;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.ServletConfig;
import model.User;
import settings.Settings;
import utils.Util;

/**
 * Servlet implementation class Login
 */
public class AjaxRequestsApi extends BaseServlet {

    private UserImpl userDao;

    @Override
    public void init(ServletConfig config) throws ServletException {
        userDao = UserImpl.getInstance();
        super.init(config);
    }

    @Override
    protected void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException {
        String type = Util.fixNull(request.getParameter("type"));
        PrintWriter out = response.getWriter();
        if ("getHeroesList".equals(type)) {
            out.print("{\"status\": \"success\", \"heroesList\":" + Util.json.toJson(ConstantTable.getHeroesList()) + "}");
            out.flush();
            return;
        }
        out.print("{\"status\": \"error\", \"msg\":\"error\"}");
        out.flush();
        return;

    }
}
